clear
version 8.0
#delimit ;
cd "Z:\interactionmodels\";                       * SET WORKING DIRECTORY;
log using addresults\electoralparties_golder.log, replace;

*     ***************************************************************** *;
*     ***************************************************************** *;
*       File-Name:      electoralparties_golder.do                      *;
*       Date:           01/09/2007                                      *;
*       Author:         MRG                                             *;
*       Purpose:        Provide interaction figures for replication     *;
*                       using Golder (2005) data.                       *;
*       Input File:     golder1.dta                                     *;
*       Output File:    electoralparties_golder.log                     *;
*       Data Output:    none                                            *;
*       Previous file:                                                  *;
*       Machine:                                                        *;
*     ****************************************************************  *;
*     ****************************************************************  *;

set mem 10m;

use getdata\golder1.dta;


*     ****************************************************************  *;
*                         Run correct Model 1                           *;
*     ****************************************************************  *;

regress elecparties_nyu logmag_nyu proximity_nyu prescandidate_nyu prox_prescandidate_nyu, robust;

*     ****************************************************************  *;
*                       Now do interaction figure                       *;
*     ****************************************************************  *;

regress elecparties_nyu  proximity_nyu prescandidate_nyu prox_prescandidate_nyu logmag_nyu, robust;

*     ****************************************************************  *;
*       Create x-axis for modifying variable (PRESCANDIDATE) = JH       *;
*     ****************************************************************  *;

generate JH=((_n-1)/10);    

replace JH=. if _n>80;

*     ****************************************************************  *;
*       Grab elements of the matrix required for calculating            *;
*       conditional coefficients and standard errors.                   *;
*     ****************************************************************  *;

matrix b=e(b);
matrix V=e(V);
scalar b1=b[1,1];
scalar b2=b[1,2];
scalar b3=b[1,3];

scalar varb1=V[1,1];
scalar varb2=V[2,2];
scalar varb3=V[3,3];
scalar covb1b3=V[1,3];
scalar covb2b3=V[2,3];


set more off;

scalar list b1 b2 b3 varb1 varb2 varb3 covb1b3 covb2b3;

*     ****************************************************************  *;
*         Create full range of conditional coefficients for proximity   *;
*     ****************************************************************  *;

gen conb=b1+b3*JH if _n<80;

set more off;

list conb in 1/20;

*     ****************************************************************  *;
*           Create full range of conditional standard errors            *;
*     ****************************************************************  *;

gen conse=sqrt(varb1+varb3*JH^2+2*covb1b3*JH)  if _n<80;
set more off;

*     ****************************************************************  *;
*               Generate confidence intervals at the 95% level          *;
*     ****************************************************************  *;
*     ****************************************************************  *;

gen a=2.00*conse;
gen top=conb+a;
gen bottom=conb-a;
set textsize 100;

*     ****************************************************************  *;
*       Graph the effect of proximity on electoral parties conditional  *;
*       on the number of presidential candidates                        *;
*     ****************************************************************  *;
      
graph twoway   line conb JH, clwidth(medium) clcolor(blue) clcolor(black)
        ||  line top  JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  line bottom JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  ,   
            xlabel(0 1 2 3 4 5 6, labsize(2.5)) 
            ylabel(-15 -10 -5 0 5, labsize(2.5))
            yscale(noline)
            xscale(noline)
            legend(col(1) order(1 2) label(1 "Estimated Causal Effect of Proximity") label(2 "95% Confidence Interval") 
                  label(3 " "))
        yline(0, lcolor(black)) yline(-5 5 -10 -15, lcolor(white))  
            title("Estimated Causal Effect of Temporally-Proximate Presidential Elections", size(4))
            subtitle(" " "Dependent Variable: Effective Number of Electoral Parties" " ", size(3))
            xtitle(Effective Number of Presidential Candidates, size(3)  )
        xsca(titlegap(2))
        ysca(titlegap(2))
            ytitle("Estimated Causal Effect of Proximity", size(3))
        scheme(s2mono) graphregion(fcolor(white));

*     ****************************************************************  *;
*                               Save picture                            *;
*     ****************************************************************  *;

translate @Graph addresults\proximity1.wmf, replace;

drop JH conb cons a top bottom;


*     ****************************************************************  *;
*           Effect of fragmentation as concentration changes            *;
*     ****************************************************************  *;

regress elecparties_nyu  fragmentation concentration frag_conc_nyu, robust;

*     ****************************************************************  *;
*       Create x-axis for modifying variable (CONCENTRATION) = JH       *;
*     ****************************************************************  *;

generate JH=((_n-1)/10);    

replace JH=. if _n>40;

*     ****************************************************************  *;
*       Grab elements of the matrix required for calculating            *;
*       conditional coefficients and standard errors.                   *;
*     ****************************************************************  *;

matrix b=e(b);
matrix V=e(V);
scalar b1=b[1,1];
scalar b2=b[1,2];
scalar b3=b[1,3];

scalar varb1=V[1,1];
scalar varb2=V[2,2];
scalar varb3=V[3,3];
scalar covb1b3=V[1,3];
scalar covb2b3=V[2,3];


set more off;

scalar list b1 b2 b3 varb1 varb2 varb3 covb1b3 covb2b3;

*     ****************************************************************  *;
*         Create full range of conditional coefficients for             *;
*       fragmentation                                                   *;
*     ****************************************************************  *;

gen conb=b1+b3*JH if _n<40;

set more off;

list conb in 1/20;

*     ****************************************************************  *;
*           Create full range of conditional standard errors            *;
*     ****************************************************************  *;

gen conse=sqrt(varb1+varb3*JH^2+2*covb1b3*JH)  if _n<40;
set more off;

*     ****************************************************************  *;
*               Generate confidence intervals at the 95% level          *;
*     ****************************************************************  *;
*     ****************************************************************  *;

gen a=2.00*conse;
gen top=conb+a;
gen bottom=conb-a;
set textsize 100;

*     ****************************************************************  *;
*       Graph the effect of fragmentation on electoral parties          *;
*       conditional on concentration                                    *;
*     ****************************************************************  *;

graph twoway   line conb JH, clwidth(medium) clcolor(black)
        ||  line top  JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  line bottom JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  ,   
            xlabel(0 1 2 3 4, labsize(2.5)) 
            ylabel(-2 -1 0 1 2, labsize(2.5))
            yscale(noline)
            xscale(noline)
            legend(col(1) order(1 2) label(1 "Estimated Causal Effect of Fragmentation") label(2 "95% Confidence Interval") label(3 "Lower bound 95% C.I.") size(3))
            yline(0, lcolor(black)) yline(-1  1 2, lcolor(white))
            title(Estimated Causal Effect of Fragmentation, size(4))
            subtitle(" " "Dependent Variable: Effective Number of Electoral Parties" " ", size(3))
        xtitle("Concentration Index", size(3))
        xsca(titlegap(2))
        ysca(titlegap(2))
            ytitle("Estimated Causal Effect of Fragmentation", size(3))
            scheme(s2mono) graphregion(fcolor(white));
            
*     ****************************************************************  *;
*                               Save picture                            *;
*     ****************************************************************  *;

translate @Graph addresults\fragmentation1.wmf, replace;

*     ****************************************************************  *;
*           I want a graph that I can use as an example in the paper    *;
*           and so I am going to use this one.                          *;
*     ****************************************************************  *;

graph twoway   line conb JH, clwidth(medium) clcolor(black)
        ||  line top  JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  line bottom JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  ,   
            xlabel(0 1 2 3 4, labsize(2.5)) 
            ylabel(-2 -1 0 1 2, labsize(2.5))
            yscale(noline)
            xscale(noline)
            legend(col(1) order(1 2) label(1 "Estimated Causal Effect of X ") label(2 "95% Confidence Interval") label(3 "Lower bound 95% C.I.") size(3))
            yline(0, lcolor(black)) yline(-1  1 2, lcolor(white))
            title(Figure 1: Estimated Causal Effect of X on Y, size(4))
            subtitle(" " "Dependent Variable: Y" " ", size(3))
        xtitle("Conditioning Variable (C)", size(3))
        xsca(titlegap(2))
        ysca(titlegap(2))
            ytitle("Estimated Causal Effect of X", size(3))
            scheme(s2mono) graphregion(fcolor(white));

*     ****************************************************************  *;
*                               Save picture                            *;
*     ****************************************************************  *;

translate @Graph addresults\example1.wmf, replace;

         

drop JH conb cons a top bottom;




*     ****************************************************************  *;
*       Institutional and sociological model - no interaction with      *;
*       logmag yet.                                                     *;
*     ****************************************************************  *;

regress elecparties_nyu  fragmentation concentration frag_conc_nyu logmag_nyu proximity_nyu 
prescandidate_nyu prox_prescandidate_nyu, robust;

*     ****************************************************************  *;
*       Create x-axis for modifying variable (CONCENTRATION) = JH       *;
*     ****************************************************************  *;

generate JH=((_n-1)/10);    

replace JH=. if _n>40;

*     ****************************************************************  *;
*       Grab elements of the matrix required for calculating            *;
*       conditional coefficients and standard errors.                   *;
*     ****************************************************************  *;

matrix b=e(b);
matrix V=e(V);
scalar b1=b[1,1];
scalar b2=b[1,2];
scalar b3=b[1,3];

scalar varb1=V[1,1];
scalar varb2=V[2,2];
scalar varb3=V[3,3];
scalar covb1b3=V[1,3];
scalar covb2b3=V[2,3];


set more off;

scalar list b1 b2 b3 varb1 varb2 varb3 covb1b3 covb2b3;

*     ****************************************************************  *;
*         Create full range of conditional coefficients for             *;
*           fragmentation                                               *;
*     ****************************************************************  *;

gen conb=b1+b3*JH if _n<40;

set more off;

list conb in 1/20;

*     ****************************************************************  *;
*           Create full range of conditional standard errors            *;
*     ****************************************************************  *;

gen conse=sqrt(varb1+varb3*JH^2+2*covb1b3*JH)  if _n<40;
set more off;

*     ****************************************************************  *;
*               Generate confidence intervals at the 95% level          *;
*     ****************************************************************  *;
*     ****************************************************************  *;

gen a=2.00*conse;
gen top=conb+a;
gen bottom=conb-a;
set textsize 100;

*     ****************************************************************  *;
*       Graph the effect of fragmentation on electoral parties          *;
*       conditional on concentration                                    *;
*     ****************************************************************  *;      
        
graph twoway   line conb JH, clwidth(medium) 
        ||  line top  JH, clpattern(dash) clwidth(thin) 
        ||  line bottom JH, clpattern(dash) clwidth(thin) 
        ||  ,   
            xlabel(0 1 2 3 4, labsize(2.5)) 
            ylabel(-2 -1 0 1 2 , labsize(2.5))
            yscale(noline)
            xscale(noline)
            legend(col(1) order(1 2) size(2.8) label(1 "Estimated Causal Effect of Fragmentation") label(2 "95% Confidence Interval") label(3 "95% C.I."))
            yline(0, lcolor(black))  yline(-1 1 2, lcolor(white)) 
            title(Estimated Causal Effect of Fragmentation, size(4))
        subtitle(" " "Dependent Variable: Effective Number of Electoral Parties" " ", size(3))
        xtitle("Concentration Index" " ", size(2.8))
            ytitle(Estimated Causal Effect of Fragmentation, size(2.8))
        xsca(titlegap(2))
        ysca(titlegap(2))
        scheme(s2mono) graphregion(fcolor(white));
        
*     ****************************************************************  *;
*                               Save picture                            *;
*     ****************************************************************  *;

translate @Graph addresults\fragmentation2.wmf, replace;


drop JH conb cons a top bottom;





*     ****************************************************************  *;
*       Institutional and sociological model - with interaction with    *;
*       logmag now.                                                     *;
*     ****************************************************************  *;

regress elecparties_nyu  fragmentation concentration logmag_nyu
         frag_conc_nyu logmag_frag_nyu logmag_conc_nyu proximity_nyu 
         prescandidate_nyu prox_prescandidate_nyu, robust;

*     ****************************************************************  *;
*       Create x-axis for modifying variable (LOGMAG) = JH       *;
*     ****************************************************************  *;

generate JH=((_n-1)/10);    
replace JH=. if _n>30;

generate str1 txt="*";


*     ****************************************************************  *;
*       Grab elements of the matrix required for calculating            *;
*       conditional coefficients and standard errors.                   *;
*     ****************************************************************  *;

matrix b=e(b);
matrix V=e(V);
scalar b1=b[1,1];
scalar b2=b[1,2];
scalar b3=b[1,3];
scalar b4=b[1,4];
scalar b5=b[1,5];
scalar b6=b[1,6];



scalar varb1=V[1,1];
scalar varb2=V[2,2];
scalar varb3=V[3,3];
scalar varb4=V[4,4];
scalar varb5=V[5,5];
scalar varb6=V[6,6];


scalar covb1b4=V[1,4];
scalar covb1b5=V[1,5];
scalar covb4b5=V[4,5];



set more off;

scalar list b1 b2 b3 b4 b5 b6 varb1 varb2 varb3 varb4 varb5 varb6 covb1b4 covb1b5 covb4b5;

*     ****************************************************************  *;
*         Create full range of conditional coefficients for             *;
*       fragmentation                                                   *;
*     ****************************************************************  *;

gen conb0=b1+b4*0+b5*JH if _n<30;
gen conb1=b1+b4*1+b5*JH if _n<30;
gen conb2=b1+b4*2+b5*JH if _n<30;
gen conb3=b1+b4*3+b5*JH if _n<30;
gen conb4=b1+b4*4+b5*JH if _n<30;

set more off;


*     ****************************************************************  *;
*           Create full range of conditional standard errors            *;
*     ****************************************************************  *;

gen conse0=sqrt(varb1 + varb4*(0^2) + varb5*(JH^2)
                + 2*0*covb1b4 + 2*JH*covb1b5 + 2*0*JH*covb4b5)  if _n<30;
                
gen conse1=sqrt(varb1 + varb4*(1^2) + varb5*(JH^2)
                + 2*1*covb1b4 + 2*JH*covb1b5 + 2*1*JH*covb4b5)  if _n<30;
                
gen conse2=sqrt(varb1 + varb4*(2^2) + varb5*(JH^2)
                + 2*2*covb1b4 + 2*JH*covb1b5 + 2*2*JH*covb4b5)  if _n<30;
                
gen conse3=sqrt(varb1 + varb4*(3^2) + varb5*(JH^2)
                + 2*3*covb1b4 + 2*JH*covb1b5 + 2*3*JH*covb4b5)  if _n<30;
                
gen conse4=sqrt(varb1 + varb4*(4^2) + varb5*(JH^2)
                + 2*4*covb1b4 + 2*JH*covb1b5 + 2*4*JH*covb4b5)  if _n<30;
                

set more off;

*     ****************************************************************  *;
*                           Create t statistics                         *;
*     ****************************************************************  *;

gen t0=conb0/conse0;
gen t1=conb1/conse1;
gen t2=conb2/conse2;
gen t3=conb3/conse3;
gen t4=conb4/conse4;

*     ****************************************************************  *;
*       Generate a variable equal to conditional betas                  *;
*     ****************************************************************  *;

gen consb0=conb0;
gen consb1=conb1;
gen consb2=conb2;
gen consb3=conb3;
gen consb4=conb4;




*     ****************************************************************  *;
*       Replace consb_ = missing if t score not bigger than cutoff      *;
*     ****************************************************************  *;

replace consb0 = . if abs(t0)<2.01;
replace consb1 = . if abs(t1)<2.01;
replace consb2 = . if abs(t2)<2.01;
replace consb3 = . if abs(t3)<2.01;
replace consb4 = . if abs(t4)<2.01;

set textsize 100;

*     ****************************************************************  *;
*       Graph the effect of fragmentation on electoral parties          *;
*       conditional on logmag                                           *;
*     ****************************************************************  *;


graph twoway   line conb0 JH , clpattern(solid) clwidth(thin)
        ||  scatter consb0 JH,  mlabel(txt) msymbol(i) mlabsize(vsmall) mlabgap(-1.0) mlabposition(11)
        ||  line conb1 JH , clpattern(solid) clwidth(thin)
        ||  scatter consb1 JH,  mlabel(txt) msymbol(i) mlabsize(vsmall) mlabgap(-1.0) mlabposition(11)
        ||  line conb2 JH , clpattern(solid) clwidth(thin)
        ||  scatter consb2 JH,  mlabel(txt) msymbol(i) mlabsize(vsmall) mlabgap(-1.0) mlabposition(11)
        ||  line conb3 JH , clpattern(solid) clwidth(thin)
        ||  scatter consb3 JH,  mlabel(txt) msymbol(i) mlabsize(vsmall) mlabgap(-1.0) mlabposition(11)        
        ||  line conb4 JH , clpattern(solid) clwidth(thin)
        ||  scatter consb4 JH,  mlabel(txt) msymbol(i) mlabsize(vsmall) mlabgap(-1.0) mlabposition(11)
        ||  ,   
            ysize(6)
            xsize(8)
            xlabel(0 1 2 3 , labsize(2.5)) 
            ylabel(-1 0 1 2 , labsize(2.5))
            yscale(noline)
            xscale(noline)
            legend(off)
            yline(0, lcolor(black)) yline(-1 1 2, lcolor(white))  
            title(Estimated Causal Effect of Fragmentation, size(4))
            xtitle(Logged Average District Magnitude, size(3))
            ytitle(Estimated Causal Effect of Fragmentation, size(3))
        xsca(titlegap(2))
        ysca(titlegap(3))
        text(1.35 3.25 "Concentration Index=4", justification(left) size(2.5))
        text(0.95 3.25 "Concentration Index=3", justification(left) size(2.5))
        text(0.55 3.25 "Concentration Index=2", justification(left) size(2.5))
        text(0.15 3.25 "Concentration Index=1", justification(left) size(2.5))
        text(-0.25 3.25 "Concentration Index=0", justification(left) size(2.5))
        text(1.9 1 "* indicates significance at the 95% level", justification(left) size(2.5))
        subtitle(" " "Dependent Variable: Effective Number of Electoral Parties" " ", size(3))
        scheme(s2mono) graphregion(fcolor(white))
        graphregion(margin(r=24));
        
*     ****************************************************************  *;
*                               Save picture                            *;
*     ****************************************************************  *;

translate @Graph addresults\fragmentation3.wmf, replace;
            

drop JH conb0 conb1 conb2 conb3 conb4 consb0 consb1 consb2 consb3 consb4 conse0 conse1 conse2 conse3 conse4 t0 t1 t2 t3 t4 txt;






*     ****************************************************************  *;
*       Institutional and sociological model - with interaction with    *;
*       logmag and now with triple interaction included.                *;
*     ****************************************************************  *;

regress elecparties_nyu  fragmentation concentration logmag_nyu 
        frag_conc_nyu logmag_frag_nyu logmag_conc_nyu 
        logmag_frag_conc_nyu proximity_nyu prescandidate_nyu 
        prox_prescandidate_nyu, robust;

*     ****************************************************************  *;
*       Create x-axis for modifying variable (LOGMAG) = JH              *;
*     ****************************************************************  *;

generate JH=((_n-1)/10);    
replace JH=. if _n>30;

generate str1 txt="*";


*     ****************************************************************  *;
*       Grab elements of the matrix required for calculating            *;
*       conditional coefficients and standard errors.                   *;
*     ****************************************************************  *;

matrix b=e(b);
matrix V=e(V);
scalar b1=b[1,1];
scalar b2=b[1,2];
scalar b3=b[1,3];
scalar b4=b[1,4];
scalar b5=b[1,5];
scalar b6=b[1,6];
scalar b7=b[1,7];
scalar b8=b[1,8];
scalar b9=b[1,9];
scalar b10=b[1,10];




scalar varb1=V[1,1];
scalar varb2=V[2,2];
scalar varb3=V[3,3];
scalar varb4=V[4,4];
scalar varb5=V[5,5];
scalar varb6=V[6,6];
scalar varb7=V[7,7];
scalar varb8=V[8,8];
scalar varb9=V[9,9];
scalar varb10=V[10,10];


scalar covb1b4=V[1,4];
scalar covb1b5=V[1,5];
scalar covb1b7=V[1,7];
scalar covb3b5=V[3,5];
scalar covb3b6=V[3,6];
scalar covb3b7=V[3,7];
scalar covb5b6=V[5,6];
scalar covb6b7=V[6,7];
scalar covb4b5=V[4,5];
scalar covb4b7=V[4,7];
scalar covb5b7=V[5,7];





set more off;

scalar list b1 b2 b3 b4 b5 b6 b7 varb1 varb2 varb3 varb4 varb5 varb6 varb7 
            covb1b4 covb1b5 covb1b7 covb4b5 covb4b7 covb5b7;

*     ****************************************************************  *;
*         Create full range of conditional coefficients for             *;
*       fragmentation                                                   *;
*     ****************************************************************  *;

gen conb0=b1+b4*0+b5*JH+b7*(0*JH) if _n<30;
gen conb1=b1+b4*1+b5*JH+b7*(1*JH) if _n<30;
gen conb2=b1+b4*2+b5*JH+b7*(2*JH) if _n<30;
gen conb3=b1+b4*3+b5*JH+b7*(3*JH) if _n<30;
gen conb4=b1+b4*4+b5*JH+b7*(4*JH) if _n<30;

set more off;


*     ****************************************************************  *;
*           Create full range of conditional standard errors            *;
*     ****************************************************************  *;

gen conse0=sqrt(varb1
                + varb4*0 + varb5*JH^2 + varb7*JH^2*(0^2)
                + 2*0*covb1b4 + 2*JH*covb1b5 + 2*0*JH*covb1b7+2*0*JH*covb4b5
                + 2*(0^2)*JH*covb4b7 + 2*0*(JH^2)*covb5b7)  if _n<30;
                
gen conse1=sqrt(varb1
                + varb4*1 + varb5*JH^2 + varb7*JH^2*(1^2)
                + 2*1*covb1b4 + 2*JH*covb1b5 + 2*1*JH*covb1b7+2*1*JH*covb4b5
                + 2*(1^2)*JH*covb4b7 + 2*1*(JH^2)*covb5b7)  if _n<30;
                
gen conse2=sqrt(varb1
                + varb4*4 + varb5*JH^2 + varb7*JH^2*(2^2)
                + 2*2*covb1b4 + 2*JH*covb1b5 + 2*2*JH*covb1b7+2*2*JH*covb4b5
                + 2*(2^2)*JH*covb4b7 + 2*2*(JH^2)*covb5b7)  if _n<30;
                
gen conse3=sqrt(varb1
                + varb4*9 + varb5*JH^2 + varb7*JH^2*(3^2)
                + 2*3*covb1b4 + 2*JH*covb1b5 + 2*3*JH*covb1b7+2*3*JH*covb4b5
                + 2*(3^2)*JH*covb4b7 + 2*3*(JH^2)*covb5b7)  if _n<30;
                
gen conse4=sqrt(varb1
                + varb4*16 + varb5*JH^2 + varb7*JH^2*(4^2)
                + 2*4*covb1b4 + 2*JH*covb1b5 + 2*4*JH*covb1b7+2*4*JH*covb4b5
                + 2*(4^2)*JH*covb4b7 + 2*4*(JH^2)*covb5b7)  if _n<30;
                
set more off;

*     ****************************************************************  *;
*                           Create t statistics                         *;
*     ****************************************************************  *;

gen t0=conb0/conse0;
gen t1=conb1/conse1;
gen t2=conb2/conse2;
gen t3=conb3/conse3;
gen t4=conb4/conse4;

*     ****************************************************************  *;
*       Generate a variable equal to conditional betas                  *;
*     ****************************************************************  *;

gen consb0=conb0;
gen consb1=conb1;
gen consb2=conb2;
gen consb3=conb3;
gen consb4=conb4;




*     ****************************************************************  *;
*       Replace consb_ = missing if t score not bigger than cutoff      *;
*     ****************************************************************  *;

replace consb0 = . if abs(t0)<2.01;
replace consb1 = . if abs(t1)<2.01;
replace consb2 = . if abs(t2)<2.01;
replace consb3 = . if abs(t3)<2.01;
replace consb4 = . if abs(t4)<2.01;

set textsize 100;


set textsize 100;

*     ****************************************************************  *;
*       Graph the effect of fragmentation on electoral parties          *;
*       conditional on logmag                                           *;
*     ****************************************************************  *;

graph twoway   line conb0 JH , clpattern(solid) clwidth(thin)
        ||  scatter consb0 JH,  mlabel(txt) msymbol(i) mlabsize(vsmall) mlabgap(-1.0) mlabposition(11)
        ||  line conb1 JH , clpattern(solid) clwidth(thin)
        ||  scatter consb1 JH,  mlabel(txt) msymbol(i) mlabsize(vsmall) mlabgap(-1.0) mlabposition(11)
        ||  line conb2 JH , clpattern(solid) clwidth(thin)
        ||  scatter consb2 JH,  mlabel(txt) msymbol(i) mlabsize(vsmall) mlabgap(-1.0) mlabposition(11)
        ||  line conb3 JH , clpattern(solid) clwidth(thin)
        ||  scatter consb3 JH,  mlabel(txt) msymbol(i) mlabsize(vsmall) mlabgap(-1.0) mlabposition(11)        
        ||  line conb4 JH , clpattern(solid) clwidth(thin)
        ||  scatter consb4 JH,  mlabel(txt) msymbol(i) mlabsize(vsmall) mlabgap(-1.0) mlabposition(11)
        ||  ,   
            ysize(6)
            xsize(8)
            xlabel(0 1 2 3, labsize(2.5)) 
            ylabel(-1 0 1 2 , labsize(2.5))
            yscale(noline)
            xscale(noline)
            legend(off)
            yline(0, lcolor(black)) yline(-1 1 2 3 4, lcolor(white)) 
            title(Estimated Causal Effect of Fragmentation, size(4))
            xtitle(Logged Average District Magnitude, size(3))
            ytitle(Estimated Causal Effect of Fragmentation, size(3))
        xsca(titlegap(2)) ysca(titlegap(4))
        text(1.8 3.3 "Concentration Index=4", justification(left) size(2.5))
        text(1.27 3.3 "Concentration Index=3", justification(left) size(2.5))
        text(0.72 3.3 "Concentration Index=2", justification(left) size(2.5))
        text(0.18 3.3 "Concentration Index=1", justification(left) size(2.5))
        text(-0.38 3.3 "Concentration Index=0", justification(left) size(2.5))
        text(2 1 "* indicates significance at the 95% level", justification(left) size(2.5))
        subtitle(" " "Dependent Variable: Effective Number of Electoral Parties" " " " ", size(3))
        scheme(s2mono) graphregion(fcolor(white))
        graphregion(margin(r=28));

*     ****************************************************************  *;
*                               Save picture                            *;
*     ****************************************************************  *;

translate @Graph addresults\fragmentation4.wmf, replace;            

set textsize 100;





*     ****************************************************************  *;
*       Proximity                                                       *;
*     ****************************************************************  *;


drop JH conb0 conb1 conb2 conb3 conb4 consb0 consb1 consb2 consb3 consb4 conse0 conse1 conse2 conse3 conse4 t0 t1 t2 t3 t4 txt;




regress elecparties_nyu  fragmentation concentration logmag_nyu frag_conc_nyu logmag_frag_nyu  
logmag_conc_nyu logmag_frag_conc_nyu proximity_nyu prescandidate_nyu prox_prescandidate_nyu, robust;

*     ****************************************************************  *;
*       Create x-axis for modifying variable (PRESCANDIDATE) = JH       *;
*     ****************************************************************  *;

generate JH=((_n-1)/10);    

replace JH=. if _n>80;

*     ****************************************************************  *;
*       Grab elements of the matrix required for calculating            *;
*       conditional coefficients and standard errors.                   *;
*     ****************************************************************  *;

matrix b=e(b);
matrix V=e(V);
scalar b1=b[1,1];
scalar b2=b[1,2];
scalar b3=b[1,3];
scalar b4=b[1,4];
scalar b5=b[1,5];
scalar b6=b[1,6];
scalar b7=b[1,7];
scalar b8=b[1,8];
scalar b9=b[1,9];
scalar b10=b[1,10];




scalar varb1=V[1,1];
scalar varb2=V[2,2];
scalar varb3=V[3,3];
scalar varb4=V[4,4];
scalar varb5=V[5,5];
scalar varb6=V[6,6];
scalar varb7=V[7,7];
scalar varb8=V[8,8];
scalar varb9=V[9,9];
scalar varb10=V[10,10];


scalar covb1b4=V[1,4];
scalar covb1b5=V[1,5];
scalar covb1b7=V[1,7];
scalar covb3b5=V[3,5];
scalar covb3b6=V[3,6];
scalar covb3b7=V[3,7];
scalar covb5b6=V[5,6];
scalar covb6b7=V[6,7];
scalar covb4b5=V[4,5];
scalar covb4b7=V[4,7];
scalar covb5b7=V[5,7];
scalar covb8b10=V[8,10];

*     ****************************************************************  *;
*         Create full range of conditional coefficients for proximity   *;
*     ****************************************************************  *;

gen conb=b8+b10*JH if _n<80;

set more off;

list conb in 1/20;

*     ****************************************************************  *;
*           Create full range of conditional standard errors            *;
*     ****************************************************************  *;

gen conse=sqrt(varb8+varb10*JH^2+2*covb8b10*JH)  if _n<80;
set more off;

*     ****************************************************************  *;
*               Generate confidence intervals at the 95% level          *;
*     ****************************************************************  *;
*     ****************************************************************  *;

gen a=2.01*conse;
gen top=conb+a;
gen bottom=conb-a;
set textsize 100;

*     ****************************************************************  *;
*       Graph the effect of proximity on electoral parties conditional  *;
*       on the number of presidential candidates                        *;
*     ****************************************************************  *;

graph twoway   line conb JH, clwidth(medium) clcolor(blue) clcolor(black)
        ||  line top  JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  line bottom JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  ,   
            xlabel(0 1 2 3 4 5 6, labsize(2.5)) 
            ylabel(5 0 5  , labsize(2.5))
            yscale(noline)
            xscale(noline)
            legend(col(1) order(1 2) label(1 "Estimated Causal Effect of Proximity") label(2 "95% Confidence Interval") 
                  label(3 " "))
        yline(0, lcolor(black)) yline(-5 5, lcolor(white))  
            title("Estimated Causal Effect of Temporally-Proximate Presidential Elections", size(4))
            subtitle(" " "Dependent Variable: Effective Number of Electoral Parties" " ", size(3))
            xtitle(Effective Number of Presidential Candidates, size(3)  )
        xsca(titlegap(2))
        ysca(titlegap(2))
            ytitle("Estimated Causal Effect of Proximity", size(3))
        scheme(s2mono) graphregion(fcolor(white));

*     ****************************************************************  *;
*                               Save picture                            *;
*     ****************************************************************  *;

translate @Graph addresults\proximity2.wmf, replace;

drop JH conb top bottom a;


*     ****************************************************************  *;
*           Now calculate the marginal causal effect of logmag as       *;
*           fragmentation changes                                       *;
*     ****************************************************************  *;


regress elecparties_nyu  fragmentation concentration logmag_nyu frag_conc_nyu logmag_frag_nyu  
logmag_conc_nyu logmag_frag_conc_nyu proximity_nyu prescandidate_nyu prox_prescandidate_nyu, robust;

*     ****************************************************************  *;
*       Create x-axis for modifying variable (FRAGMENTATION) = JH       *;
*     ****************************************************************  *;

generate JH=((_n-1)/10);    
replace JH=. if _n>100;

generate str1 txt="*";


*     ****************************************************************  *;
*       Grab elements of the matrix required for calculating            *;
*       conditional coefficients and standard errors.                   *;
*     ****************************************************************  *;

matrix b=e(b);
matrix V=e(V);
scalar b1=b[1,1];
scalar b2=b[1,2];
scalar b3=b[1,3];
scalar b4=b[1,4];
scalar b5=b[1,5];
scalar b6=b[1,6];
scalar b7=b[1,7];
scalar b8=b[1,8];
scalar b9=b[1,9];
scalar b10=b[1,10];




scalar varb1=V[1,1];
scalar varb2=V[2,2];
scalar varb3=V[3,3];
scalar varb4=V[4,4];
scalar varb5=V[5,5];
scalar varb6=V[6,6];
scalar varb7=V[7,7];
scalar varb8=V[8,8];
scalar varb9=V[9,9];
scalar varb10=V[10,10];


scalar covb1b4=V[1,4];
scalar covb1b5=V[1,5];
scalar covb1b7=V[1,7];
scalar covb3b4=V[3,4];
scalar covb3b5=V[3,5];
scalar covb3b6=V[3,6];
scalar covb3b7=V[3,7];
scalar covb4b5=V[4,5];
scalar covb4b7=V[4,7];
scalar covb5b6=V[5,6];
scalar covb5b7=V[5,7];
scalar covb6b7=V[6,7];



set more off;

scalar list b1 b2 b3 b4 b5 b6 b7 varb1 varb2 varb3 varb4 varb5 varb6 varb7 
            covb1b4 covb1b5 covb1b7 covb4b5 covb4b7 covb5b7;

*     ****************************************************************  *;
*         Create full range of conditional coefficients for logmag      *;
*     ****************************************************************  *;

gen conb0=b3+b5*JH+b6*0+b7*(0*JH) if _n<100;
gen conb1=b3+b5*JH+b6*1+b7*(1*JH) if _n<100;
gen conb2=b3+b5*JH+b6*2+b7*(2*JH) if _n<100;
gen conb3=b3+b5*JH+b6*3+b7*(3*JH) if _n<100;
gen conb4=b3+b5*JH+b6*4+b7*(4*JH) if _n<100;

set more off;


*     ****************************************************************  *;
*           Create full range of conditional standard errors            *;
*     ****************************************************************  *;

gen conse0=sqrt(varb3
                + varb5*JH^2 + varb6*(0^2) + varb7*(JH^2)*(0^2)
                + 2*JH*covb3b5 + 2*0*covb3b6 + 2*0*JH*covb3b7 + 2*0*JH*covb5b6
                + 2*0*(JH^2)*covb5b7) + 2*(0^2)*JH*covb6b7  if _n<100;
                
gen conse1=sqrt(varb3
                + varb5*JH^2 + varb6*(1^2) + varb7*(JH^2)*(1^2)
                + 2*JH*covb3b5 + 2*1*covb3b6 + 2*1*JH*covb3b7 + 2*1*JH*covb5b6
                + 2*1*(JH^2)*covb5b7) + 2*(1^2)*JH*covb6b7  if _n<100;
                
gen conse2=sqrt(varb3
                + varb5*JH^2 + varb6*(2^2) + varb7*(JH^2)*(2^2)
                + 2*JH*covb3b5 + 2*2*covb3b6 + 2*2*JH*covb3b7 + 2*2*JH*covb5b6
                + 2*2*(JH^2)*covb5b7) + 2*(2^2)*JH*covb6b7  if _n<100;
                
gen conse3=sqrt(varb3
                + varb5*JH^2 + varb6*(3^2) + varb7*(JH^2)*(3^2)
                + 2*JH*covb3b5 + 2*3*covb3b6 + 2*3*JH*covb3b7 + 2*3*JH*covb5b6
                + 2*3*(JH^2)*covb5b7) + 2*(3^2)*JH*covb6b7  if _n<100;
                
gen conse4=sqrt(varb3
                + varb5*JH^2 + varb6*(4^2) + varb7*(JH^2)*(4^2)
                + 2*JH*covb3b5 + 2*4*covb3b6 + 2*4*JH*covb3b7 + 2*4*JH*covb5b6
                + 2*4*(JH^2)*covb5b7) + 2*(4^2)*JH*covb6b7  if _n<100;
                               
set more off;

*     ****************************************************************  *;
*                           Create t statistics                         *;
*     ****************************************************************  *;

gen t0=conb0/conse0;
gen t1=conb1/conse1;
gen t2=conb2/conse2;
gen t3=conb3/conse3;
gen t4=conb4/conse4;

*     ****************************************************************  *;
*       Generate a variable equal to conditional betas                  *;
*     ****************************************************************  *;

gen consb0=conb0;
gen consb1=conb1;
gen consb2=conb2;
gen consb3=conb3;
gen consb4=conb4;




*     ****************************************************************  *;
*       Replace consb_ = missing if t score not bigger than cutoff      *;
*     ****************************************************************  *;

replace consb0 = . if abs(t0)<2.01;
replace consb1 = . if abs(t1)<2.01;
replace consb2 = . if abs(t2)<2.01;
replace consb3 = . if abs(t3)<2.01;
replace consb4 = . if abs(t4)<2.01;

set textsize 100;

*     ****************************************************************  *;
*       Graph the effect of logmag on electoral parties conditional on  *;
*       fragmentation                                                   *;
*     ****************************************************************  *;

graph twoway   line conb0 JH , clpattern(solid) clwidth(vthin)
        ||  scatter consb0 JH,  mlabel(txt) msymbol(i) mlabsize(vsmall) mlabgap(-1.0) mlabposition(11)
        ||  line conb1 JH , clpattern(solid) clwidth(vthin)
        ||  scatter consb1 JH,  mlabel(txt) msymbol(i) mlabsize(vsmall) mlabgap(-1.0) mlabposition(11)
        ||  line conb2 JH , clpattern(solid) clwidth(vthin)
        ||  scatter consb2 JH,  mlabel(txt) msymbol(i) mlabsize(vsmall) mlabgap(-1.0) mlabposition(11)
        ||  line conb3 JH , clpattern(solid) clwidth(vthin)
        ||  scatter consb3 JH,  mlabel(txt) msymbol(i) mlabsize(vsmall) mlabgap(-1.0) mlabposition(11)        
        ||  line conb4 JH , clpattern(solid) clwidth(vthin)
        ||  scatter consb4 JH,  mlabel(txt) msymbol(i) mlabsize(vsmall) mlabgap(-1.0) mlabposition(11)
        ||  ,   
            ysize(6)
            xsize(8)
            title(Estimated Causal Effect of Logged Average District Magnitude, size(4) justification(center))
            subtitle(" " "Dependent Variable: Effective Number of Electoral Parties" " " " ", size(3) justification(center))
            xlabel(0 1 2 3 4 5 6 7 8 9 10, labsize(2.5)) 
            ylabel(-2 -1 0 1 2 3 4 , labsize(2.5))
            yscale(noline)
            xscale(noline)
            yline(0, lcolor(black)) yline(-2 -1  1 2 3 4 , lcolor(white)) 
            xtitle(Fragmentation Index, size(3))
            ytitle("Estimated Causal Effect of Logged Average" "District Magnitude", size(3))
            xsca(titlegap(2))
            ysca(titlegap(4.5))
            text(3.6 11.40 "Concentration Index=4", justification(left) size(2.5))
            text(2.7 11.40 "ConcentrationIndex=3", justification(left) size(2.5))
            text(1.7 11.40 "Concentration Index=2", justification(left) size(2.5))
            text(0.8 11.40 "Concentration Index=1", justification(left) size(2.5))
            text(-0.2 11.40 "Concentrationn Index=0", justification(left) size(2.5))
            text(3.9 2.7 "* indicates significance at the 95% level", justification(left) size(2.5))
            legend(off)
            scheme(s2mono) graphregion(fcolor(white))
            graphregion(margin(r=28));

*     ****************************************************************  *;
*                               Save picture                            *;
*     ****************************************************************  *;

translate @Graph addresults\logmag1.wmf, replace;

log close;
exit;
